unit DokumentDetajlFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DokumentFrm, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxEdit, DB, cxDBData, DBClient, MConnect, alBaseDataSet,
  StdActns, ActnList, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
  StdCtrls, ExtCtrls, cxEditRepositoryItems, cxContainer, cxDropDownEdit,
  cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, cxMaskEdit, cxCalendar,
  cxDBEdit, cxTextEdit, cxDBEditRepository, cxGridBandedTableView,
  cxGridDBBandedTableView, DokumentVnosFrm, ImgList, PoslovanjeSrv_TLB,
  cxDataStorage, cxExtEditRepositoryItems, cxCheckComboBox,
  cxDBCheckComboBox, kdbinfo, kdbstruc, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmDokumentDetajl = class(TfrmDokumentVnos)
    grdPostavka: TcxGrid;
    grdlvlPostavka: TcxGridLevel;
    scnPostavka: TSharedConnection;
    cdsPostavka: TBaseDataSet;
    dtsrcPostavka: TDataSource;
    grdtvPostavka: TcxGridDBBandedTableView;
    grdtvPostavkaID: TcxGridDBBandedColumn;
    grdtvPostavkaRazredID: TcxGridDBBandedColumn;
    grdtvPostavkaRefID: TcxGridDBBandedColumn;
    rpstMainPostavkaID: TcxEditRepositoryMaskItem;
    rpstMainPostavkaRazredID: TcxEditRepositoryMaskItem;
    rpstMainPostavkaRefID: TcxEditRepositoryMaskItem;
    procedure OnNewRecord(DataSet: TDataSet);
    procedure OnEnter(Sender: TObject);
    procedure OnExit(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure Deinitialize; override;
    procedure Initialize; override;
    procedure Loaded; override;
    procedure SetDefaultControl; override;
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  frmDokumentDetajl: TfrmDokumentDetajl;

implementation

uses
  MainFrm;

{$R *.dfm}

{ TfrmTemeljnica }

constructor TfrmDokumentDetajl.Create(AOwner: TComponent);
begin
  inherited;
  with grdtvPostavka do
  begin
    NavigatorButtons.ConfirmDelete := False;
    OptionsBehavior.FocusFirstCellOnNewRecord := True;
    OptionsBehavior.GoToNextCellOnEnter := True;
    OptionsBehavior.FocusCellOnTab := True;
    OptionsCustomize.BandMoving := False;
    OptionsCustomize.ColumnFiltering := False;
    OptionsCustomize.ColumnVertSizing := False;
    OptionsCustomize.ColumnSorting := False;
    OptionsData.CancelOnExit := False;
    OptionsData.DeletingConfirmation := False;
    OptionsView.ColumnAutoWidth := True;
    OptionsView.Footer := True;
    OptionsView.Indicator := True;
    OptionsView.BandHeaders := False;
    OptionsView.GroupByBox := False;
    OptionsView.HeaderAutoHeight := True;
  end;
end;

procedure TfrmDokumentDetajl.Deinitialize;
begin
  cdsPostavka.Close;
  inherited;
end;

procedure TfrmDokumentDetajl.Initialize;
begin
  inherited;
  cdsPostavka.Open;
end;

procedure TfrmDokumentDetajl.Loaded;
var
  i: Integer;
begin
  inherited;
  with grdtvPostavka do
  begin
    grdtvPostavkaID.Visible := False;
    grdtvPostavkaID.Options.Filtering := False;
    grdtvPostavkaRazredID.Visible := False;
    grdtvPostavkaRazredID.Options.Filtering := False;
    grdtvPostavkaRefID.Visible := False;
    grdtvPostavkaRefID.Options.Filtering := False;
    for i := 0 to ColumnCount - 1 do
    begin
      Columns[i].Position.BandIndex := 0;
      Columns[i].Position.RowIndex := 0;
      Columns[i].Position.ColIndex := i;
    end;
  end;
end;

procedure TfrmDokumentDetajl.OnEnter(Sender: TObject);
begin
  inherited;
  if Sender = grdPostavka then
  begin
    KeyPreview := False;
    DataSource := dtsrcPostavka;
  end;
end;

procedure TfrmDokumentDetajl.OnExit(Sender: TObject);
begin
  inherited;
  if Sender = grdPostavka then
  begin
    DataSource := RootDataSource;
    KeyPreview := True;
  end;
end;

procedure TfrmDokumentDetajl.OnNewRecord(DataSet: TDataSet);
begin
  inherited;
  if DataSet = cdsPostavka then
  begin
    DataSet.FieldByName('REF_ID').Value := cdsMain.FieldByName('ID').Value;
  end;
end;

procedure TfrmDokumentDetajl.SetDefaultControl;
begin
  inherited;
  if DataSource = dtsrcPostavka then
    grdtvPostavka.Controller.FocusFirstAvailableItem;
end;

end.
